package com.nd.mobile.study.view;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.TabHost;
import android.widget.TextView;

import com.nd.mobile.study.R;
import com.nd.mobile.study.common.BaseActivity;

public class AboutActivity extends BaseActivity {
	private TextView	mHeaderTitle;
	private TabHost		mTabHost;
	private ViewPager	mViewPager;
	private SimpleTabsAdapter	mTabsAdapter;

	private String[]	mTabLabels;
	private WebView[]	mWebViews;
	
	private static final String INDEX_01 ="file:///android_asset/index01.htm";//学校简介
	private static final String INDEX_02 ="file:///android_asset/index02.htm";//学校领导
	private static final String INDEX_03 ="file:///android_asset/index03.htm";//机构设置
	private static final String INDEX_04 ="file:///android_asset/index04.htm";//办学网络

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.pager_tab);
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		mTabsAdapter.setTabs(mTabLabels);
	}

	@Override
	protected void initViews() {
		initHeader();
		mHeaderTitleTv.setText(R.string.about_title);
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup();
	}

	@Override
	protected void setFieldValues() {
		super.setFieldValues();
		mTabsAdapter = new AboutTabsAdapter(this, mTabHost, mViewPager);
		mTabLabels = getResources().getStringArray(R.array.about_tab);
		mWebViews = new WebView[mTabLabels.length];
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		boolean result = false;
		if (KeyEvent.KEYCODE_BACK == keyCode) {
			result = true;
			finish();
		}
		return result;
	}

	private class AboutTabsAdapter extends SimpleTabsAdapter {

		public AboutTabsAdapter(Activity activity, TabHost tabHost, ViewPager pager) {
			super(activity, tabHost, pager);
		}

		@Override
		protected void initPageView(int position) {
			switch(position){
				case 0:
					mWebViews[position].loadUrl(INDEX_01);
					break;
				case 1:
					mWebViews[position].loadUrl(INDEX_02);
					break;
				case 2:
					mWebViews[position].loadUrl(INDEX_03);
					break;
				case 3:
					mWebViews[position].loadUrl(INDEX_04);
					break;
				default:
					mWebViews[position].loadUrl(INDEX_01);
					break;
			}
			
		}

		@Override
		protected View getPageView(int position) {
			if (null == mWebViews[position]) {
				mWebViews[position] = new WebView(AboutActivity.this);
				mWebViews[position].setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
			}
			return mWebViews[position];
		}
	}
}